$('.right-titleicon').on("click",function(e){
	projectVM.showMenulist()
})
let that;
projectVM = new Vue({
	el: "#content",
	data: {
		disabled:true,
		showSelect:false,
		menuList:[
			{name:'投入',path:'goIn.html'},{name:'退出',path:'goOut.html'},{name:'列表',path:'index.html'},
		],
		typeList:[{name:'变压器1'},{name:'变压器2'},{name:'变压器3'},{name:'变压器4'},],
		showSubmit:false,
		onStatus:'',
		selectText:'变压器1',
		result:'',
		showMenu:false,
		showMorebtn:false,
		advance:'',
		showAdd:false,
		show_popup:false,
		OperateStaff:"",//操作人
		TutelageStaff:"",//监护人
		listin:[{}],
		fileList:[],
		listout:[],
		currentIndex:1,
		PopPicker:"",
		dataJson:"",//上一页列表中的Item数据
		faultCategory:'',//故障类别
		mainTainLevel:"",//维修等级
		mainTainAction:"",//维修动作
		textMeThod:"",//检测方式
		itemDetail:"",//详情数据
		faultText:"",//故障类型 文字
		repairLevelText:"",//维修等级 文字
		repairActionText:"",//维修动作 文字
		textMeThodText:"",//测试方法 文字
		pushData:{faultNotice:{},faultTicket:{},currentUser:{},materielInfoList:{}},
	},
	created: function() {
		that = this;
		//hu获取页面必要的参数
		let config = mui.neioConfig.getNeioConfig();
		let key = config.KEYS.PARTS;
		let data = mui.neioConfig.getStorage(key);
		let dataJson = JSON.parse(data)
		that.dataJson = dataJson;
		console.log("元器件："+data)
		//初始化 上传 参数JSON
		that.getCode();
		that.getInDetail(dataJson);
	},
	methods: {

		//获取元器件列表
		getInDetail(data){
			let config = mui.neioConfig.getNeioConfig();
			let url = config.URL.getWorkOrderIdByPage
			let params = {}
			params.workOrderId = data.workOrderId;
			params.ticketId = data.ticketId;
			params.current = that.currentIndex;
			params.pageSize = '1000';
			
			
			mui.neiosRequst.httpRequst(url,params,function(ret){
				console.log("元器件成功回掉："+JSON.stringify(ret))
				if(ret.code == 0){
					that.listin = ret.data.records;
				}
			},function(err){
				console.log("失败回掉："+JSON.stringify(err))
			})
		},
		//获取码表
		getCode(){
			let dictCodes = 'FAULT_CATEGORY,MAINTAIN_LEVEL,MAINTAIN_ACTION,TEXT_METHOD';
			mui.neiosCommon.queryDict(dictCodes,function(data){
				if (data != '') {
					console.log("码表数据："+JSON.stringify(data))
					that.faultCategory = data.FAULT_CATEGORY;
					that.mainTainLevel = data.MAINTAIN_LEVEL;
					that.mainTainAction = data.MAINTAIN_ACTION;
					that.textMeThod = data.TEXT_METHOD
					that.getFaultDetail()
				}
			})
		},
		//获取详情
		getFaultDetail(){
			let itemdata = that.dataJson;
			let persionData = JSON.parse(localStorage.getItem("neiosUser"));
			let config = mui.neioConfig.getNeioConfig();
			let url = config.URL.getFaultTicketById
		
			let userInfor = {};
			userInfor.userId = persionData.userId;
			userInfor.name = persionData.name;
			
			let params = {}
			params.ticketId = itemdata.ticketId;
			params.currentUser = userInfor;
			
			mui.neiosRequst.httpRequst(url,params,function(ret){
				console.log("故障详情："+JSON.stringify(ret))
				let data = that.pushData;
				if(ret.code == 0){
					//====================界面赋值=================
					that.itemDetail = ret.data.faultTicketVo;
					that.getFault(that.itemDetail.faultClassification)
					that.getrepairLevel(that.itemDetail.repairLevel)
					that.getrepairAction(that.itemDetail.repairAction)
					that.gettestMethod(that.itemDetail.testMethod)
					
					data.faultTicket.faultReason = ret.data.faultTicketVo.faultReason;//故障原因
					data.faultTicket.reportNo = ret.data.faultTicketVo.reportNo;//故障分析报告
					data.faultTicket.lossPower = ret.data.faultTicketVo.lossPower;//发电量损失
					data.faultTicket.repairCost = ret.data.faultTicketVo.lossPower;//维修成本
					data.faultTicket.total = ret.data.faultTicketVo.total;//合计
					
					
					//===================初始化上传数据==========================
					data.faultTicket.ticketId = ret.data.faultTicketVo.ticketId;//故障记录工作票主键
					data.faultTicket.lastEnterCode = that.getUserInfo().userId;//最后补录人id	
					data.faultTicket.lastEnterName = that.getUserInfo().name;//最后补录人姓名
					data.faultTicket.isEnterFinish = "";// 是否补录完成
					data.faultTicket.remark ="";// 备注
					data.faultTicket.client ="";// 客户id
					data.faultTicket.dataSource = "NEIOS_APP"+localStorage.getItem("currVersion");// 数据来源
					data.faultTicket.status = "";// 业务状态
					data.faultTicket.dataStatus = "";// 是否有效
					data.faultTicket.modifyBy = that.getUserInfo().userId;//修改人员id
					data.faultTicket.modifyStaffName = that.getUserInfo().name;// 修改人员姓名
					data.faultTicket.modifyDate = that.dateFormate();//修改时间
					
					data.faultNotice.faultNoticeId = ret.data.faultTicketVo.faultNoticeId;//故障记录通知单主键
					data.faultNotice.windTurbineType = that.itemDetail.windTurbineType;//故障记录通知单主键
					data.faultNotice.remark = "";//备注
					data.faultNotice.client = "";//客户id
					data.faultNotice.dataSource = "NEIOS_APP"+localStorage.getItem("currVersion");//数据来源
					data.faultNotice.status = "";//业务状态
					data.faultNotice.dataStatus = "1";//是否有效
					data.faultNotice.modifyBy = that.getUserInfo().userId;//修改人员id
					data.faultNotice.modifyStaffName = that.getUserInfo().name;//修改人员姓名
					data.faultNotice.modifyDate = that.dateFormate();//修改时间
					
					data.materielInfoList = that.listin;
					
					let userInfor = {};
					userInfor.userId = that.getUserInfo().userId;
					userInfor.name = that.getUserInfo().name;
					data.currentUser = userInfor;

					that.pushData = data;
				}
			},function(err){
				console.log("失败回掉："+JSON.stringify(err))
			})
			
		},
		
		//获取故障类别
		getFault(itemCodeStr){
			that.faultCategory.forEach((item,i)=>{
				if(itemCodeStr == item.itemCode){
					console.log("----------------故障:"+item.itemText+"---------------------")
					that.faultText =  item.itemText;
				}
			})
		},
		//获取维修等级
		getrepairLevel(itemCodeStr){
			that.mainTainLevel.forEach((item,i)=>{
				if(itemCodeStr == item.itemCode){
					console.log("----------------维修等级:"+item.itemText+"---------------------")
					that.repairLevelText =  item.itemText;
				}
			})
		},
		//获取维修动作
		gettestMethod(itemCodeStr){
			that.textMeThod.forEach((item,i)=>{
				if(itemCodeStr == item.itemCode){
					console.log("----------------维修等级:"+item.itemText+"---------------------")
					that.textMeThodText =  item.itemText;
				}
			})
		},
		//测试方法
		getrepairAction(itemCodeStr){
			that.mainTainAction.forEach((item,i)=>{
				if(itemCodeStr == item.itemCode){
					console.log("----------------维修等级:"+item.itemText+"---------------------")
					that.repairActionText =  item.itemText;
				}
			})
		},
		
		//保存数据
		saveData(){
			let config = mui.neioConfig.getNeioConfig();
			let url = config.URL.saveOrUpdateFault
			let params = that.pushData;
			
			console.log("提交数据："+JSON.stringify(params))
			mui.neiosRequst.httpRequst(url,params,function(ret){
				console.log(JSON.stringify(ret))
				if(ret.code == 0){
					mui.toast(ret.msg)
					setTimeout(that.goBack,700);
				}
				if( ret.code == 1){
					mui.toast(ret.msg)
				}
			})
		},
		//获取用户信息-新建投退记录的情况下
		getUserInfo(){
			let user = JSON.parse(localStorage.getItem("neiosUser"))
			return user;
		},

		//返回上一页
		goBack(){
			mui.back()
		},
		//弹出菜单
		/**
		 * @param {Object} type 0 故障类别 1 补录记录信息 2维修等级 3维修动作 4测试方法 
		 */
		showP(type){ 
			let paramData = that.pushData;
			let param = []
			if('0' == type){
				that.faultCategory.forEach((item,i) =>{
					item.value = item.itemCode;
					item.text = item.itemText;
				})
				param = that.faultCategory
			}
			if('1' == type){
				param = [{value:'0',text:'机械(含液压)'},{value:'1',text:'电气(含住空)'},{value:'2',text:'其他'}]
			}
			if('2' == type){
				that.mainTainLevel.forEach((item,i) =>{
					item.value = item.itemCode;
					item.text = item.itemText;
				})
				param = that.mainTainLevel
			}
			if('3' == type){
				that.mainTainAction.forEach((item,i) =>{
					item.value = item.itemCode;
					item.text = item.itemText;
				})
				param = that.mainTainAction
			}
			if('4' == type){
				that.textMeThod.forEach((item,i) =>{
					item.value = item.itemCode;
					item.text = item.itemText;
				})
				param = that.textMeThod
			}
			 that.PopPicker.setData(param);
			 that.PopPicker.show(function (selectItems) {
				 if('0' == type){
					 that.faultText = selectItems[0].itemText;
					 paramData.faultNotice.faultClassification = selectItems[0].itemCode;
				 }
				 
				 if('2' == type){
					 that.repairLevelText = selectItems[0].itemText;
					 paramData.faultTicket.repairLevel = selectItems[0].itemCode;
				 }
				 
				 if('3' == type){
				 	that.repairActionText = selectItems[0].itemText;
				 	paramData.faultTicket.repairAction = selectItems[0].itemCode;
				 }
				 if('4' == type){
				 	that.textMeThodText = selectItems[0].itemText;
				 	paramData.faultTicket.testMethod = selectItems[0].itemCode;
				 }
				 
				 that.pushData = paramData;
				 // console.log("故障数据："+JSON.stringify(that.pushData))
			    // console.log(JSON.stringify(selectItems));//智子
			    // console.log(selectItems[0].value);//zz 
			  })
		},
		// 获取时间
		dateFormate () {
			return mui.neiosCommon.transTime(new Date(),"min")
		},
		//获取毫秒
		getMiu(){
			let date = that.dateFormate();
			var arr = date.split(/[- : \/]/);
			var startDate = Date.parse(new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4]));
			return startDate;
		},
		//左上角菜单显示隐藏
		showMenulist(){
			this.showMenu?this.showMenu=false:this.showMenu=true 
		},
		navTo(e){
			mui.openWindow({
				url: e,
				id: e,
				extras: {},
			waiting: {
				autoShow: false
			}
			});
		},
	},
	
	})
	mui.init()
	mui.plusReady(function () {
	    projectVM.PopPicker = new mui.PopPicker();
	})